#include "PCH.h"
#include "GameApp.h"
#include "global.h"
#include "MainMenuScene.h"
#include "HeroCreateScene.h"
#include "GameScene.h"
#include "MapEditor.h"
#include "MapGenScene.h"

const char *GS_MAINMENU = "MainMenu";
const char *GS_HEROCREATE = "HeroCreate";
const char *GS_GAME = "Game";
const char *GS_MAPEDITOR = "MapEditor";
const char *GS_MAPGENTEST = "MapGen";

void GameApp::Go()
{
	if (_init())
		_run();

	_close();
}

bool GameApp::_init()
{
	_config.Load("");

	if (!InitEngine(_config.descengine))
		return false;

	GameFont = new Font("Data/font.ttf");
	if (!GameFont)
		return false;

	_imgmgr = new ImageMgr();
	_imgmgr->Init();

	MainMenuScene *MMscene = new MainMenuScene(GS_MAINMENU);
	_scenemgr.AddScene(GS_MAINMENU, MMscene);

	HeroCreateScene *HCscene = new HeroCreateScene(GS_HEROCREATE);
	_scenemgr.AddScene(GS_HEROCREATE, HCscene);
	
	GameScene *Gscene = new GameScene(GS_GAME);
	_scenemgr.AddScene(GS_GAME, Gscene);

	MapEditor *MEscene = new MapEditor(GS_MAPEDITOR);
	_scenemgr.AddScene(GS_MAPEDITOR,MEscene);

	MapGenScene *MPGscene = new MapGenScene(GS_MAPGENTEST);
	_scenemgr.AddScene(GS_MAPGENTEST,MPGscene);

	_scenemgr.SetScene(GS_MAINMENU);
	_scenemgr.SetScene(GS_MAPGENTEST);

	return true;
}

void GameApp::_run()
{
	while (_scenemgr.Run());
}

void GameApp::_close()
{
	_imgmgr->Close();
	_DELETE (GameFont);
	_scenemgr.Close();
	QuitEngine();
}